"""meet"""
from flask import Blueprint, request
from util.response import response
import util.meet

meet_api = Blueprint('meet_api', __name__)


@meet_api.route("/api/meet", methods=["GET"])
def room_index():
    """会议室列表"""
    res = util.meet.room_list()
    resp = sorted(res["data"]["rooms"], key=lambda x: x["roomName"])
    return response(res["code"], res["msg"], {"data": resp})


@meet_api.route("/api/device", methods=["GET"])
def device_index():
    """设备列表"""
    res = util.meet.device_list()
    return response(res["code"], res["msg"], {"data": res["data"]["devices"]})


@meet_api.route("/api/meet", methods=["POST"])
def room_store():
    """添加｜修改 会议室"""
    data = request.get_json()
    res = util.meet.room_store(data)
    return response(res['code'], res['msg'], res['data'])


@meet_api.route("/api/meet", methods=["DELETE"])
def room_destroy():
    """删除会议室"""
    data = request.get_json()
    res = util.meet.room_destroy(data)
    return response(res['code'], res['msg'], res['data'])


@meet_api.route("/api/meet/device", methods=["POST"])
def room_device_store():
    """会议室关联设备"""
    data = request.get_json()
    res = util.meet.room_device_store(data)
    return response(0, "success", res)
